﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AddCommonCode.ascx.cs"
    Inherits="Viewer.Code.UserControls.AddCommonCode" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<ext:Window ID="wdAddCommonCode" runat="server" Width="400" AutoHeight="true" Modal="true"
    Hidden="true" BodyCssClass="window">
    <Items>
        <ext:Container runat="server" Layout="FormLayout" LabelWidth="100">
            <Items>
            <ext:Hidden ID="CheckTonTai" runat="server" />
                <ext:Hidden ID="hdType" runat="server" />
                <ext:Hidden ID="hdLoaiMa" runat="server" />
                <ext:Hidden ID="hdCodeId" runat="server" />
                <ext:TextField ID="txtCodeString" runat="server" FieldLabel="Chuỗi Mã" Width="200" />
                <ext:TextField ID="txtCodeKey" runat="server" FieldLabel="Khóa Mã" Width="200" ReadOnly="true" />
                <ext:TextField ID="txtCodeValue" runat="server" FieldLabel="Giá Trị Mã" Width="200" />
                <ext:ComboBox ID="cbbCodeIdType" runat="server" DisplayField="CodeValue" ValueField="CodeID"
                    Width="200" FieldLabel="Loại mã">
                    <Store>
                        <ext:Store ID="storeLoaiMa" runat="server">
                            <Reader>
                                <ext:JsonReader IDProperty="CodeID">
                                    <Fields>
                                        <ext:RecordField Name="CodeIDCha" />
                                        <ext:RecordField Name="CodeValue" />
                                        <ext:RecordField Name="CodeID" />
                                    </Fields>
                                </ext:JsonReader>
                            </Reader>
                        </ext:Store>
                    </Store>
                    <Triggers>
                        <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                    </Triggers>
                    <Listeners>
                        <Select Handler="this.triggers[0].show();" />
                        <BeforeQuery Handler="this.triggers[0][ this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                        <TriggerClick Handler="if (index == 0) { this.clearValue(); this.triggers[0].hide(); }" />
                    </Listeners>
                </ext:ComboBox>
                <ext:ComboBox ID="cboCodeIDCha" runat="server" DisplayField="CodeValue" ValueField="CodeID"
                    Width="200" FieldLabel="Mã Cha">
                    <Store>
                        <ext:Store ID="storeCodeCha" runat="server">
                            <Reader>
                                <ext:JsonReader IDProperty="CodeID">
                                    <Fields>
                                        <ext:RecordField Name="CodeIDCha" />
                                        <ext:RecordField Name="CodeID" />
                                        <ext:RecordField Name="CodeValue" />
                                    </Fields>
                                </ext:JsonReader>
                            </Reader>
                        </ext:Store>
                    </Store>
                    <Triggers>
                        <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                    </Triggers>
                    <Listeners>
                        <Select Handler="this.triggers[0].show();" />
                        <BeforeQuery Handler="this.triggers[0][ this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                        <TriggerClick Handler="if (index == 0) { this.clearValue(); this.triggers[0].hide(); }" />
                    </Listeners>
                </ext:ComboBox>
                <ext:TextField ID="txtGhiChu" runat="server" FieldLabel="Ghi Chú" Width="200" />
            </Items>
        </ext:Container>
    </Items>
    <Buttons>
    
        <ext:Button ID="btnSave" runat="server" Text="Lưu" Icon="Disk">
            <Listeners>
                <Click Handler="
                       if(#{hdType}.getValue()=='AddNew')
                       {             
                       Ext.net.Mask.show();          
                            Ext.each(#{storeDulieuDetail}.data.items, function(record) {
                                if(record.data.CodeValue==#{txtCodeValue}.getValue().trim())
                                {
                                      Ext.MessageBox.alert('Lỗi', 'Giá trị này đã tồn tại.');  
                                      #{CheckTonTai}.setValue('TonTai');
                                }
                           });
                       } 
                  " />
            </Listeners>
            <DirectEvents>
                <Click OnEvent="btnSave_Click">
                </Click>
            </DirectEvents>
        </ext:Button>
        <ext:Button ID="Button1" runat="server" Text="Đóng" Icon="Cancel">
            <Listeners>
                <Click Handler="#{wdAddCommonCode}.hide();" />
            </Listeners>
        </ext:Button>
    </Buttons>
</ext:Window>
